﻿@using Coralcode.Adapter.TextualAnalyzer.Entity.Domains
@using Coralcode.Base.Utils
@using CoralNode.Core.Entity.Domains.Prototype
@using CoralNode.Core.Entity.Enums
@using CoralNode.MvcClient.Helper
<!--left-->
@{
    ViewData["curr"] = "indexaction";
    var searchFieldsSetting = ViewBag.SearchFieldsSetting as IList<SearchIndexFieldDomain>;
}
@Html.IncludePage("CoralAdmin/prototype", "_Left", new { current = "prototype" })
<div id="pbody">
    <div class="extra">
        <div class="pbody_top">
            <span class="ico ico_setting_system"></span><span class="t t_c">索引管理</span>
        </div>
        <div id="main">
            @Html.IncludePage("CoralAdmin/Prototype", "_tab", new { prototypeId = ViewBag.PrototypeId })
            <div class="">
                @using (Html.BeginForm("SetFieldIndexAction", "Prototype", FormMethod.Post)) {
                    <div class="tablelist_style1" data-js="tabellist_style1">
                        <div class="funsearch p_1 pl_2 pr_2 extra_normal">
                            <div class="select_owner w_11 mr_1" data-meta="{value:'@ViewBag.PrototypeId',name:'PrototypeId', btn:'<span class=\'ico ico_slide_down\'></span>' , clickbtn:'<span class=\'ico ico_slide_up\'></span>'}">
                                <ul>
                                    @foreach (var item in @ViewBag.PrototypeList) {
                                        <li data-value="@item.Id"><a href="/m/prototype/setfieldindexaction?PrototypeId=@item.Id">@item.Title</a>
                                        </li>
                                    }
                                </ul>
                            </div>
                        </div>
                        <div class="p_1 pt_0">
                            <div class="js_tab">
                                <a href="javascritp:">扩展字段</a>
                                <a href="javascript:">系统字段</a>
                            </div>
                            <div class="pt_1">
                                <div>
                                    <table cellpadding="0" cellspacing="0">
                                        <tr class="exclude">
                                            <th width="100" align="center">ID</th>
                                            <th width="300" align="left">字段名</th>
                                            <th width="100" align="center">字段类型</th>
                                            <th>索引设置</th>
                                        </tr>
                                        @foreach (PrototypeFieldDomain item in ViewBag.Fields) {
                                            <tr>
                                                <td>@item.Id</td>
                                                <td class="td_left">@item.Title</td>
                                                @{
                                            var filedType = EnumUtil.GetEnumDescription(NodeEnums.BasicFieldType, @item.FieldType);
                                            if (string.IsNullOrEmpty(filedType)) {
                                                filedType = EnumUtil.GetEnumDescription(NodeEnums.FunctionFieldType, item.FieldType);
                                            }
                                                }
                                                <td width="td_left">@filedType</td>
                                                <td>
                                                    <select name="field_@item.FieldName">
                                                        @foreach (var keyvalue in ViewBag.IndexActionList) {
                                                            var setting = searchFieldsSetting.FirstOrDefault(n => n.FieldName.Equals(item.Prototype.Code + "." + item.FieldName, StringComparison.CurrentCultureIgnoreCase));
                                                            <option value="@keyvalue.Value" @if (setting != null && setting.FieldType == keyvalue.Value) {
                                                                                            @String.Format("selected=selected")
                                                                                            } >@keyvalue.Key</option>
                                                        }
                                                    </select>
                                                </td>
                                            </tr>
                                        }

                                    </table>
                                </div>
                                <div>
                                    <table cellpadding="0" cellspacing="0">
                                        <tr class="exclude">
                                            <th width="100" align="center">序号</th>
                                            <th width="300" align="left">名称</th>
                                            <th width="100" align="center">字段类型</th>
                                            <th>索引设置</th>
                                        </tr>
                                        <tr>
                                            <td>1</td>
                                            <td class="td_left">标题</td>
                                            <td width="td_left">系统内置</td>
                                            <td>
                                                <select name="sysfield_Title">
                                                    @foreach (var keyvalue in ViewBag.IndexActionList) {
                                                        var setting = searchFieldsSetting.FirstOrDefault(n => n.FieldName == "Title");
                                                        <option value="@keyvalue.Value" @if (setting != null && setting.FieldType == keyvalue.Value) {
                                                                                            @String.Format("selected=selected")
                                                                                        } >@keyvalue.Key</option>
                                                    }
                                                </select></td>
                                        </tr>
                                        <tr>
                                            <td>2</td>
                                            <td class="td_left">分类Id</td>
                                            <td width="td_left">系统内置</td>
                                            <td>
                                                <select name="sysfield_CategoryId">
                                                    @foreach (var keyvalue in ViewBag.IndexActionList) {
                                                        var setting = searchFieldsSetting.FirstOrDefault(n => n.FieldName == "CategoryId");
                                                        <option value="@keyvalue.Value" @if (setting != null && setting.FieldType == keyvalue.Value) {
                                                                                            @String.Format("selected=selected")
                                                                                        } >@keyvalue.Key</option>
                                                    }
                                                </select></td>
                                        </tr>
                                        <tr>
                                            <td>3</td>
                                            <td class="td_left">原型Id</td>
                                            <td width="td_left">系统内置</td>
                                            <td>
                                                <select name="sysfield_PrototypeId">
                                                    @foreach (var keyvalue in ViewBag.IndexActionList) {
                                                        var setting = searchFieldsSetting.FirstOrDefault(n => n.FieldName == "PrototypeId");
                                                        <option value="@keyvalue.Value" @if (setting != null && setting.FieldType == keyvalue.Value) {
                                                                                            @String.Format("selected=selected")
                                                                                        } >@keyvalue.Key</option>
                                                    }
                                                </select></td>
                                        </tr>
                                        <tr>
                                            <td>4</td>
                                            <td class="td_left">发布时间</td>
                                            <td width="td_left">系统内置</td>
                                            <td>
                                                <select name="sysfield_CreateTime">
                                                    @foreach (var keyvalue in ViewBag.IndexActionList) {
                                                        var setting = searchFieldsSetting.FirstOrDefault(n => n.FieldName == "CreateTime");
                                                        <option value="@keyvalue.Value" @if (setting != null && setting.FieldType == keyvalue.Value) {
                                                                                            @String.Format("selected=selected")
                                                                                        } >@keyvalue.Key</option>
                                                    }
                                                </select></td>
                                        </tr>
                                    </table>
                                </div>

                            </div>
                        </div>

                    </div>
                    @Html.Hidden("prototypeId", (long)ViewBag.PrototypeId)
                    <div class="global_fun p_2">
                        <label class="mr_2">
                            <input name="rebuildIndex" class="checkbox" type="checkbox" value=""><span>重建索引</span></label>
                        <input type="submit" class="btn_1" value="提交" />
                    </div>
                }
            </div>
        </div>
    </div>
</div>
<script>
    $(function () {
        $(".js_tab").each(function () {
            var $this = $(this);
            $this.tabs($this.next().children());
        });
    })
</script>
